<div class="form-container">
    <form name="new_photo_form" method="post" enctype="multipart/form-data" action="{if isset($new_photo_form_action)}{$new_photo_form_action}{/if}">
        <input type="file" name="photo" />

        <div class="btn-box-single">
            <button>Загрузить</button>
        </div>
    </form>
    <div class="form-label single-photo">Загрузить одно фото</div>
</div>

<div class="form-container">
    <div class="hint">
        <strong>Рекомендации:</strong> использовать имена файлов без пробелов и русских букв
    </div>
    <form name="new_photos_form">
        <div class="file-select">
            <input type="file" name="multiload" />
        </div>
    </form>
    <div class="form-label multiple-photo">Загрузить несколько фото</div>
</div>

<input name="grid_unit" value="{if isset($grid_unit)}{$grid_unit}{/if}" type="hidden" />
<input name="grid_name" value="{if isset($grid_name)}{$grid_name}{/if}" type="hidden" />

<table id='{if isset($grid_unit)}{$grid_unit}{/if}_grid'></table>
<div id='{if isset($grid_unit)}{$grid_unit}{/if}_pager'></div>

{if isset($photo_grid)}{$photo_grid}{/if}



{*}TODO вынести этот код в внешний скрипт {/*}
<script>
    $( "input[name=multiload]" ).parent().prepend( "<div class='btn-box'><button name='valim_optom' class='upload-multiple-files'>Загрузить</button></div>" );
    $( "input[name=multiload]" ).parent().prepend( "<div class='multiload-box'></div>" );


    $("input[name=multiload]").fileupload({
        url:"{$smarty.const.PUBLIC_URL}/repairs/multiload",
        success:function(dat){
            if(dat.status == 'ok') {

                var text = $('.multiload-box').html();

                var item = "<div class='upload-item'>" +
                        "<span>"+ dat.filename +"</span>" +
                        "       <img src='"+dat.file+"'  />" +
                        "   </div>";
                $('.multiload-box').html(text + item);
            }
        },
        dataType:'json'
    });

    function multisave(e){

        data = 'save'

        $.ajax({
            type: "POST",
            url: "{$smarty.const.PUBLIC_URL}/{if isset($unit)}{$unit}{/if}/multisave",
            data: data,
            success: function(dat){
                jQuery("#" + "{if isset($grid_name)}{$grid_name}{/if}").trigger('reloadGrid');
                $('.multiload-box').html('');
            },
            dataType: 'json'
        });

    }

    $("button[name=valim_optom]").on('click',multisave);

</script>
